<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>文本框</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <meta name="generator" content="www.leipi.org" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-ie6.css">
    <![endif]-->
    <!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css">
    <![endif]-->
    <link rel="stylesheet" href="leipi.style.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript" src="../../../../jquery/jquery-1.8.3.js"></script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
     <tr>
        <th><span>控件名称</span><span class="label label-important">*</span></th>
        <th><span>字体大小</span> </th>
    </tr>
    <tr>
        <td><input id="orgname" type="text" placeholder="必填项"/></td>
        <td><input id="orgfontsize" type="text"  value="" class="input-small span1" placeholder="auto"/> px</td>
    </tr>
    <tr>
        <th><span>数据源</span></th>
        <th><span>字段</span> </th>
    </tr>
    <tr>
        <!--update-begin--Author:zzl  Date:20151106 for：数据源及字段可选 -->

        <td>
            <select id="datasource"></select>
        </td>
        <td>
            <select id="field">
                <option selected value=''>请先选择数据源</option>
            </select>
        </td>
        <!--update-end--Author:zzl  Date:20151106 for：数据源及字段可选 -->
    </tr>
    <tr>
        <th><span>输入框样式</span> </th>
        <th><span>增强</span> </th>
    </tr>
    <tr>
        <td>
            宽 <input id="orgwidth" type="text" value="300" class="input-small span1" placeholder="auto"/> px
            &nbsp;&nbsp;
            高 <input id="orgheight" type="text" value="80" class="input-small span1" placeholder="auto"/> px
        </td>
        <td> <label class="checkbox"><input id="orgrich" type="checkbox"  /> 富文本形式 </label> </td>
    </tr>
        <tr>
            <th><span>检验规则</span> </th>
            <th></th>
        </tr>
        <tr>
            <td>
                <!-- update-start--Author:jg_renjie  Date:20151022 for：增加datatype属性 -->
                <select type="text" id="datatype" name="datatype" value="" >
                </select>
                <!-- update-start--Author:jg_renjie  Date:20151022 for：增加datatype属性 -->
            </td>
            <td>
                <label class="checkbox inline"> </label>
            </td>
        </tr>
    <tr>
        <td colspan="2">
            <label for="orgvalue">默认值</label>
            <textarea class="input-block-level" rows="3" id="orgvalue" placeholder="多行文本框默认值..."></textarea>
        </td>
    </tr>
    </table>
</div>
<script type="text/javascript">
var oNode = null,thePlugins = 'textarea';
var contentPath="../../../../../";
window.onload = function() {
    if( UE.plugins[thePlugins].editdom ){
        oNode = UE.plugins[thePlugins].editdom;
        var gValue = oNode.getAttribute('value').replace(/&quot;/g,"\""),gTitle=oNode.getAttribute('title').replace(/&quot;/g,"\""),gFontSize=oNode.getAttribute('orgfontsize'),gWidth=oNode.getAttribute('orgwidth'),gHeight=oNode.getAttribute('orgheight'),gRich=oNode.getAttribute('orgrich');
        
        gValue = gValue==null ? '' : gValue;
        gTitle = gTitle==null ? '' : gTitle;
        
        var arr1= oNode.getAttribute('autofield');
		if(arr1){
			arr1= arr1.split('.');
			var field = arr1[1]==null?'':arr1[1];
            var id = '';
            editor.ready(function() {
                id = editor.queryCommandValue('serverparam').id; //返回参数值键值对的对象
            });
            $.post(
                    contentPath+'autoFormController.do?getFormField',
                    {dbName:arr1[0],autoFormId:id},
                    function(data){
                        data = $.parseJSON(data);
                        $('#field').html('');
                        $('#field').html(data.msg);
                        $('#field').val(field);
                        $("#datasource").val(arr1[0]);
                    });
        }
        
        $G('orgvalue').value = gValue;
        $G('orgname').value = gTitle;
        if ( gRich == '1' ) {
            $G('orgrich').checked = true ;
        }
        $G('orgfontsize').value = gFontSize;
        $G('orgwidth').value = gWidth;
        $G('orgheight').value = gHeight;
        var datatype=oNode.getAttribute('datatype');
        $G('datatype').value =datatype;
        loadDataType( datatype);
    }else{
        loadDataType( $G('datatype').value);
    }

}
dialog.oncancel = function () {
    if( UE.plugins[thePlugins].editdom ) {
        delete UE.plugins[thePlugins].editdom;
    }
};
dialog.onok = function (){
    <!--update-begin--Author:zzl  Date:20151108 for：控件名称为空时优先使用字段名称 -->
    if($G('orgname').value==''){
        var selectedField=$('#field').find("option:selected");
        var flag=false;
        if(selectedField.length>0){
            selectedField=selectedField.get(0);
            if(selectedField.value!=''){
                $G('orgname').value=selectedField.text;
                flag=true;
            }
        }
        if(!flag){
            alert('请输入控件名称');
            $G('orgname').focus();
            return false;
        }
    }
    var datatype = $G('datatype').value;
    <!--update-end--Author:zzl  Date:20151108 for：控件名称为空时优先使用字段名称 -->
    var gValue=$G('orgvalue').value.replace(/\"/g,"&quot;"),gTitle=$G('orgname').value.replace(/\"/g,"&quot;"),gFontSize=$G('orgfontsize').value,gWidth=$G('orgwidth').value,gHeight=$G('orgheight').value;
    var datasource=$G('datasource').value;
    var field=$G('field').value;
    <!--update-begin--Author:zzl  Date:20151106 for：数据源及字段可选 -->
    if(datasource !='' && field ==''){
        alert('请选择字段');
        return false;
    }
    var name= getName(datasource,field,gTitle);
    <!--update-end--Author:zzl  Date:20151106 for：数据源及字段可选 -->
    if( !oNode ) {
        try {
            var html = '<textarea ';
            html += ' title = "' + gTitle + '"';
            html += ' name = "leipiNewField"';
            html += ' leipiPlugins = "'+thePlugins+'"';
            html += ' datatype = "'+datatype+'"';
            html += ' value = "' + gValue + '"';
            if( datasource != '' ){
            	html +=' autofield="'+datasource+(field!=''?('.'+field):'') +'"';
            }
            if ( $G('orgrich').checked ) {
                html += ' orgrich = "1"';
            } else {
                html += ' orgrich = "0"';
            }
            if( gFontSize != '' ) {
                html += ' orgfontsize = "' + gFontSize + '"';
            } else {
                html += ' orgfontsize = ""';
            }
            if( gWidth != '' ) {
                html += ' orgwidth = "' + gWidth + '"';
            } else {
                html += ' orgwidth = ""';
            }
            if(gHeight != '') {
                html += ' orgheight = "' + gHeight + '"';
            } else {
                html += ' orgheight = ""';
            }
            
            html += ' style = "';
            if( gFontSize != '' ) {
                html += 'font-size:' + gFontSize + 'px;';
            }
            if( gWidth != '' ) {
                html += 'width:' + gWidth + 'px;';
            }
            if( gHeight != '' ) {
                html += 'height:' + gHeight + 'px;';
            }
            
            html += '">';
            html += gValue + '</textarea>';
            editor.execCommand('insertHtml',html);
        } catch (e) {
            try {
                editor.execCommand('error');
            } catch ( e ) {
                alert('控件异常，请到 [雷劈网] 反馈或寻求帮助！');
            }
            return false;
        }
    } else {
        oNode.setAttribute('title', gTitle);
        oNode.setAttribute('value',gValue);
        oNode.setAttribute('name',name);
        oNode.setAttribute('datatype',datatype);
        oNode.innerHTML = gValue;
        if( $G('orgrich').checked ) {
            oNode.setAttribute('orgrich', 1);
        } else {
            oNode.setAttribute('orgrich', 0);
        }
        
        if( gFontSize != '' ) {
            oNode.style.fontSize = gFontSize+ 'px';
            oNode.setAttribute('orgfontsize',gFontSize );
        }else{
            oNode.setAttribute('orgfontsize', '');
        }
        if( gWidth != '' ) {
            oNode.style.width = gWidth+ 'px';
            oNode.setAttribute('orgwidth',gWidth );
        }else{
            oNode.setAttribute('orgwidth', '');
        }
        if( gHeight != '' ) {
            oNode.style.height = gHeight+ 'px';
            oNode.setAttribute('orgheight',gHeight );
        }else{
            oNode.setAttribute('orgheight', '');
        }
      	 if( datasource != '' ){
            	oNode.setAttribute('autofield',datasource+(field!=''?('.'+field):'') );
            }else{
            	oNode.setAttribute('autofield','');
            }
        delete UE.plugins[thePlugins].editdom;
    }
};
function getName(datasource,field,title){
    if(datasource !='' && field !=''){
        return datasource+'.'+field;
    } else {
        return title;
    }
}
<!--update-begin--Author:zzl  Date:20151106 for：数据源及字段可选 -->
$(function(){
    var id = '';
    editor.ready(function() {
        id = editor.queryCommandValue('serverparam').id; //返回参数值键值对的对象
    });
    $.post(
            contentPath+'autoFormController.do?getFormDb',
            {autoFormId:id},
            function(data){
                data = $.parseJSON(data);
                $('#datasource').html(data.msg);
            });
    //2.2 绑定change事件,并填充字段
    $("#datasource").change(function(){
        var dbId = $(this).val();
        $.post(
                contentPath+'autoFormController.do?getFormField',
                {dbName:dbId,autoFormId:id},
                function(data){
                    data = $.parseJSON(data);
                    $('#field').html('');
                    $('#field').html(data.msg);
                });
    });
    $("#field").change(function(){
        if(this.value!='')
            $G('orgname').value= $(this).find("option:selected")[0].text;
    });


});
<!--update-end--Author:zzl  Date:20151106 for：数据源及字段可选 -->
function loadDataType(val){
    $("#datatype").empty();
    $("#datatype").append("<option value=''>无</option>");
    $.ajax({
        url:contentPath+"systemController.do?typeGrid&",
        data:{typegroupid:"4028838850c35b6a0150c37251e00002",field:"id,typename,typecode"},
        type:"post",
        dataType:"json",
        success:function(data){
            var results=data.rows;
            $.each(results,function(i,dict){
                $("#datatype").append("<option value='"+dict.typecode+"'>"+dict.typename+"</option>");
            })
            if(val)
                $($G('datatype')).find("option[value='"+val+"']").attr("selected","selected");
        }
    });
}
</script>
</body>
</html>